#include<bits/stdc++.h>
#define LL long long
#define SZ(x) ((LL)(x.size()))
#define all(x) (x).begin(),(x).end()
using namespace std;
inline LL read(){
  LL q=0,w=1;char ch=getchar();
  while(ch>'9' || ch<'0'){if(ch=='-')w=-1;ch=getchar();}
  while(ch>='0'&&ch<='9'){q=q*10+(ch-'0');ch=getchar();}
  return q*w;
}
void write(LL x){
  if(x<0){putchar('-');x=(-x);}
  if(x>9)write(x/10);
  putchar('0'+x%10);
}
inline void writeln(LL x){write(x);puts("");}
inline void writecs(LL x){write(x);putchar(' ');}

const LL N = 10050+95 , L = 20+2 ;
LL n,m,TC;vector<LL>E[N];LL jmp[L][N],fa[N],dep[N];

struct Edge{LL to,nxt;}e[N];LL head[N],tot;void add_e(LL u,LL v){e[++tot].to=v;e[tot].nxt=head[u];head[u]=tot;return ;}
LL dfn[N],low[N],tim,seq[N];
void dfs(LL x){
  dfn[x]=++tim;seq[tim]=x;
  for(LL i=head[x];i;i=e[i].nxt){LL y=e[i].to;dfs(y);}
  low[x]=tim;return ;
}
LL K;bool vis[N];LL f[N][5],g[N],h[5];vector<LL>tr[N];bitset<N>type;
void DFS(LL x){
  g[x]=0;for(LL a=0;a<=K;a++)f[x][a]=0;
  f[x][0]=1;g[x]=1;
  for(auto y:tr[x]){
    DFS(y);LL c=0;
    for(LL z=fa[y];z!=x;z=fa[z])c+=((type[z]==0)?(1):(0));
    f[y][1]+=(g[y]*c);
    for(LL a=0;a<=K;a++)h[a]=0;
    for(LL a=0;a<=K;a++)
      for(LL b=0;a+b<=K;b++)h[a+b]+=(f[x][a]*f[y][b]);
    for(LL a=0;a<=K;a++)f[x][a]=h[a];
  }
  if(vis[x]){for(LL a=0;a<=K;a++)f[x][a]=0;}
  if(type[x]==0)f[x][1]++;
  vis[x]=0;
  return ;
}
bitset<N>ok[N],ban[N];
int main(){
  freopen("build.in","r",stdin);
  freopen("build.out","w",stdout);
  n=read();m=read();TC=read();vector<LL>deg(n+2);
  for(LL i=1;i<=m;i++){LL u=read(),v=read();E[u].push_back(v);}

  {
    for(LL x=1;x<=n;x++)for(auto y:E[x])deg[y]++;
    queue<LL>q;q.push(1);
    while(!q.empty()){
      LL x=q.front();q.pop();ok[x][x]=1;
      for(auto y:E[x]){
	deg[y]--;ok[y]=(ok[y]|ok[x]);
	if(!deg[y])q.push(y);
      }
    }
  }

  for(LL i=1;i<=n;i++)fa[i]=-1;
  for(LL x=1;x<=n;x++)for(auto y:E[x])deg[y]++;
  auto make_fa=[&](LL x){
		 assert(fa[x]!=-1);
		 dep[x]=dep[fa[x]]+1;jmp[0][x]=fa[x];
		 for(LL k=1;k<=20;k++)jmp[k][x]=jmp[k-1][jmp[k-1][x]];
		 return ;
	       };
  auto get_lca=[&](LL x,LL y){
		 if(dep[x]<dep[y])swap(x,y);
		 for(LL k=20;k>=0;k--)
		   if(dep[jmp[k][x]]>=dep[y])x=jmp[k][x];
		 if(x==y)return x;
		 for(LL k=20;k>=0;k--)
		   if(jmp[k][x]!=jmp[k][y]){x=jmp[k][x];y=jmp[k][y];}
		 return fa[x];
	       };
  
  queue<LL>q;q.push(1);
  
  while(!q.empty()){
    LL x=q.front();q.pop();
    if(x==1)fa[x]=0;
    make_fa(x);ban[x]=ban[fa[x]];ban[x][x]=1;
    for(auto y:E[x]){
      if(fa[y]==-1)fa[y]=x;
      fa[y]=get_lca(fa[y],x);
      deg[y]--;if(!deg[y])q.push(y);
    }
  }
  for(LL i=2;i<=n;i++)add_e(fa[i],i);
  dfs(1);
  for(LL i=1;i<=n;i++)ban[i]=(ban[i]^ok[i]);

  while(TC--){
    K=read();LL c=read();vector<LL>a(c),vc;
    for(LL i=0;i<c;i++){a[i]=read();vis[a[i]]=1;}
    type.reset();
    for(LL i=0;i<c;i++)type=(type|ban[a[i]]);
    for(LL i=0;i<c;i++)
      for(LL j=0;j<c;j++)
	if(a[i]!=a[j]&&ok[a[i]][a[j]])vis[get_lca(a[i],a[j])]=1;
    
    vc=a;sort(all(vc),[&](LL x,LL y){return dfn[x]<dfn[y];});
    for(LL i=SZ(vc)-1;i>0;i--)vc.push_back(get_lca(vc[i-1],vc[i]));
    vc.push_back(1);
    sort(all(vc),[&](LL x,LL y){return dfn[x]<dfn[y];});
    vc.erase(unique(all(vc)),vc.end());
    vector<LL>st;
    for(auto x:vc){
      while(SZ(st)&&low[st.back()]<dfn[x])st.pop_back();
      if(SZ(st))tr[st.back()].push_back(x);
      st.push_back(x);
    }
    
    DFS(1);writeln(f[1][K]);
    for(auto x:vc)tr[x].clear();
  }
  return 0;
}
